<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>添加联系人</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
		<link rel="stylesheet" type="text/css" href="styles.css">
		-->
		<script type="text/javascript" src="./jQuery/jquery-1.9.1.js"></script>
		<script type="text/javascript">
	/*AJAX*/
	$(".ajax.load")
			.load(
					"http://www.cnblogs.com/yeer/archive/2009/06/10/1500682.html .post",

					function(responseText, textStatus, XMLHttpRequest) {

						this;//在这里this指向的是当前的DOM对象，即$(".ajax.load")[0] 

						//alert(responseText);//请求返回的内容
						//alert(textStatus);//请求状态：success，error
						//alert(XMLHttpRequest);//XMLHttpRequest对象
					});

	$.get("./Ajax.aspx", {
		Action : "get",
		Name : "lulu"
	}, function(data, textStatus) {

		//返回的 data 可以是 xmlDoc, jsonObj, html, text, 等等.
		this; // 在这里this指向的是Ajax请求的选项配置信息，请参考下图
		alert(data);

		//alert(textStatus);//请求状态：success，error等等。

		//当然这里捕捉不到error，因为error的时候根本不会运行该回调函数
		//alert(this);
	});

	Response.ContentType = "application/json";

	Response.Write("{result: '" + Request["Name"] + ",你好！(这消息来自服务器)'}");
	//jQuery 代码： 
	$.post("Ajax.aspx", {
		Action : "post",
		Name : "lulu"
	},

	function(data, textStatus) {

		// data 可以是 xmlDoc, jsonObj, html, text, 等等.
		//this; // 这个Ajax请求的选项配置信息，请参考jQuery.get()说到的this
		alert(data.result);

	}, "json");

	var xmlHttp;
	function createXmlHttpRequest() {
		if (window.XMLHttpRequest) {
			xmlHttp = new XMLHttpRequest();
		} else {
			try {
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (ex) {
				}
			}
		}
	}

	function getDeptemp() {
		if (xmlHttp == null) {
			createXmlHttpRequest();
		}
		var s = document.getElementById("deptSelect");

		xmlHttp.open("POST", "//doUser?deptno=" + s.value, true);
		xmlHttp.onreadystatechange = callback;
		xmlHttp.send();
	}
	function callback() {
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			selectEmp
		}
	}
</script>

	</head>

	<body>
		<div id="header">
			<span>添加联系人</span>${depts }
		</div>
		<div id="center">
			<form target="yxg_center"
				action="/SBD_OASystem/yxg/msg!addGroup.action" method="post">
				<label>
					请选择部门：
				</label>
				<select id="deptSelect" onchange="getDeptemp()">
					<c:forEach items="${depts }" var="dept">
						<option value="${dept.deptno }">
							${dept.dname }
						</option>
					</c:forEach>
				</select>
				<label>
					请选择联系人：
				</label>
				<select id="selectEmp">
					<c:forEach items="${dept.emps }" var="aEmp">
						<option value="${aEmp.empno }" />${aEmp.ename }</option>
					</c:forEach>
				</select>
				<label>
					请选择分组：
				</label>
				<select>
					<c:forEach items="${tgroups }" var="aGroup">
						<option value="${aGrouop.groupid }">
							${aGrouop.gname }
						</option>
					</c:forEach>
				</select>
				<input type="submit" value="添 加">
			</form>
		</div>
		<div id="footer"></div>
	</body>
</html>
